package org.jgs1904.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.jgs1904.dao.RegionDao;
import org.jgs1904.entity.Region;
import org.jgs1904.util.DataSourceUtil;

/**
 * 区划数据操作类
 * 
 * @author junki
 * @date 2020年3月26日
 */
public class RegionDaoImpl implements RegionDao {

	@Override
	public List<Region> selectProvince() throws SQLException {

		QueryRunner qr = new QueryRunner(DataSourceUtil.getDataSource());

		String sql = "select * from region where level = 1";

		return qr.query(sql, new BeanListHandler<>(Region.class));
	}

	@Override
	public List<Region> selectRegionByParentId(String parentId) throws SQLException {
		QueryRunner qr = new QueryRunner(DataSourceUtil.getDataSource());

		String sql = "select * from region where parent_id = ?";

		return qr.query(sql, new BeanListHandler<>(Region.class), parentId);
	}

}
